package 二叉树相关问题;

import java.util.ArrayList;
import java.util.List;

public class 递增顺序查找树 {

    public TreeNode increasingBST(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        traverse(root,list);
        TreeNode rootNode = new TreeNode(list.get(0));
        TreeNode tem=rootNode;
        for (int i = 1; i < list.size(); i++) {
            tem.right=new TreeNode(list.get(i));
            tem=tem.right;
        }
        return rootNode;
    }

    private void traverse(TreeNode root, List<Integer> list) {
        if (root==null)
            return;
        traverse(root.left,list);
        list.add(root.val);
        traverse(root.right,list);
    }
}
